package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_TEXT;
import static xj.model.uml.UMLModelConstants.ATTR_TYPE;
import xj.meta.AbstractModelElement;

public class Comment extends AbstractModelElement {

  public Comment() {
    this(null, null);
  }

  public Comment(String text) {
    this(null, text);
  }

  public Comment(String type, String text) {
    setType(type);
    setText(text);

    destructable = false;
    preserved = true;
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
    setAttribute(ATTR_TYPE, type);
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
    setAttribute(ATTR_TEXT, text);
  }

  @Override
  public String toString() {
    return "Comment: type=" + type + " text=" + text;
  }

  @Override
  protected boolean asElement(String attrName) {
    if (attrName != null) {
      return (attrName.equals(ATTR_TEXT));
    }
    return false;
  }

  @Override
  protected boolean inCDATASection(String name) {
    return asElement(name);
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    Comment c = (Comment) super.clone();
    c.setType(type);
    c.setText(text);
    return c;
  }

  protected String type;

  protected String text;

}
